using System.Collections;
using UnityEngine;

public class EnemyAreaBehavior : MonoBehaviour
{
	private enum MobState
	{
		Agresive = 0,
		Pasive = 1,
		Chase = 2
	}

	public AreaLevel currentLevel;

	public float aggressiveDistance = 1f;

	public float chasingDistance = 50f;

	public float distance;

	private EnemyBehavior enemyBehavior;

	private void Awake()
	{
		enemyBehavior = GetComponent<EnemyBehavior>();
	}

	private void OnEnable()
	{
		StartCoroutine(myUpdate());
	}

	private void OnDisable()
	{
		StopAllCoroutines();
	}

	private IEnumerator myUpdate()
	{
		while (true)
		{
			if (!Application.isLoadingLevel && enemyBehavior != null && enemyBehavior.playerTarget != null && enemyBehavior.isAggressive && GameController.instance.playerScript.CanBeAttacked())
			{
				distance = Vector3.Distance(base.transform.position, enemyBehavior.playerTarget.transform.position);
				if (distance < aggressiveDistance)
				{
					enemyBehavior.SwitchEnemyState(EnemyState.Aggressive);
				}
				else if (distance < chasingDistance)
				{
					enemyBehavior.SwitchEnemyState(EnemyState.Chasing);
				}
				else
				{
					enemyBehavior.SwitchEnemyState(EnemyState.Passive);
				}
			}
			yield return null;
		}
	}
}
